<template>
  <mu-container class="pos-r">
    <mu-row class="padt10">
      <mu-paper :z-depth="1" style="width: 100%" class="round5 pad5">
        <mu-flex align-items="center">
          <mu-flex>
            <mu-button icon @click="$goback()">
              <mu-icon value="arrow_back"></mu-icon>
            </mu-button>
          </mu-flex>
          <mu-flex fill><h3>快速录单</h3></mu-flex>
          <mu-flex>
            <div class="padr10">
              <mu-button small fab color="primary" @click="submit()">
                <mu-icon value="save"></mu-icon>
              </mu-button>
            </div>
          </mu-flex>
        </mu-flex>
      </mu-paper>
    </mu-row>
    <mu-row class="padt10 pos-r">
      <mu-paper class="pad10" style="width: 100%" :z-depth="1">
        <div class="pad10">
          <div>
            <!--        表单-->
            <formCreator ref="form" :form.sync="form" :items="items" :openEdit="true"
                         labelPosition="left"></formCreator>
            <!--        表单-->
            <!--            <mu-row :gutter="true">-->
            <!--              <mu-col span="12">-->
            <!--                <mu-text-field v-model="text" class="" label="数据" placeholder="粘入文本" multi-line :rows="10" :rows-max="10" full-width></mu-text-field>-->
            <!--              </mu-col>-->
            <!--            </mu-row>-->
            <mu-row align-items="center" justify-content="center">
              <div class="tac">
                <span class="" v-for="date,index in dates">
                  <mu-button fab small color="success" v-clipboard:copy="date.day" v-clipboard:success="onCopy">
                    <div class="fs12">{{date.num}}</div>
                  </mu-button>
                  <span class="pad3" v-if="index % 7 ==6">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
                  <br v-if="index % 14 ==13">
                </span>
              </div>

            </mu-row>
            <mu-row class="mart10">
              <mu-button full-width @click="submit()" color="primary">提交并自动安排生产</mu-button>
            </mu-row>
          </div>
          <div>
            <!--            <mu-paper :z-depth="2" style="width: 100%" class="mar5" v-for="item,index in questions" :key="index">-->
            <!--              <div class="bdda pad2">{{item.title}}</div>-->
            <!--              <div class="bdda pad2" v-for="str,idx in item.choice" :key="idx">{{latters[idx]}}:{{str}}</div>-->
            <!--              <div class="bdda pad2">{{item.choiceSet}}</div>-->
            <!--              <div class="bdda pad2">{{item.intro}}</div>-->
            <!--              <div>-->
            <!--                <mu-button @click="importQ(index)">导入</mu-button>-->
            <!--              </div>-->
            <!--            </mu-paper>-->
          </div>
        </div>
      </mu-paper>
    </mu-row>
  </mu-container>

</template>

<script>
  import api from '@/assets/js/api'
  import formCreator from '@/components/FormCreator/Creator/Creator'
  import entity from '@/components/FormItem/entity'
  import entityViewer from '@/components/FormItem/entityViewer'
  import com from '../../../assets/js/com'

  export default {
    name: 'fast',
    components: {formCreator, entity, entityViewer},
    data() {
      return {
        id: undefined,
        active: 0,
        text: '',
        curIndex: '',
        curCopy: '',
        form: {},
        items: {},
        points: [],
        dates: [],
        latters: ['A', 'B', 'C', 'D', 'E', 'F', 'G']
      }
    },
    created() {
      let _this = this
      api.get('/admin/StreamOrder/fast/form', {}, function (res) {
        console.log(res)
        _this.form = res.d.show.entity
        _this.items = res.d.show.form
        _this.dates = res.d.dates
      })
      api.get("/api/streamPoints", {}, (res) => {
        console.log(res)
        this.points = res.d
      })
    },
    mounted() {
    },
    methods: {
      submit() {
        let text = this.text
        let _this = this
        this.$refs.form.$refs.form.validate().then((result) => {
          console.log('form valid: ', result)
          if (!result) {
            _this.$toast.error('请检查表单是否完整')
          } else {
            this.loading = true

            api.post('/admin/StreamOrder/fast/submit', _this.form, function (res) {
              console.log(res.d)
              _this.questions = res.d
              if (res.s == 1){
                com.showToast(res.i)
                setTimeout(()=>{
                  _this.$goto(res.d)
                },500)
              }else {
                com.showToast("系统异常")
              }
            })
          }
        })


      },
      onCopy(value) {
        com.showToast('复制成功')
        if (com.isTrue(this.curIndex) && com.isTrue(this.form[value])){
          // this.$set()
          this.form[this.curIndex] = value
        }
      },
      textFocus(index){
        // this.curIndex = index
      }
    },
    watch: {}
  }
</script>

<style scoped>

</style>
